/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024.
 * Description: EulerOS fastsched Header
 * Create: 2024-06-15
 */

#ifndef LINUX_EULEROS_FASTSCHED_H
#define LINUX_EULEROS_FASTSCHED_H

#include <linux/sched.h>

#ifdef CONFIG_EULEROS_FAST_SCHED
#define FAST_SCHED_DISABLE	0
#define FAST_SCHED_ENABLE	1

extern const struct file_operations proc_fast_sched_operations;

DECLARE_PER_CPU(struct tick_sched, tick_cpu_fastsched);
extern int fast_sched_enable(struct task_struct *p, int enable);
extern void fast_idle_irq_enter(void);
extern void fast_idle_irq_exit(void);
extern void fast_idle_account_update_idle(int cpu, u64 *last_update_time,
	ktime_t *idle, ktime_t now);
extern void fast_idle_account_update_iowait(int cpu, u64 *last_update_time,
	ktime_t *iowait, ktime_t now);
extern void fast_idle_account_add_idle(int cpu, ktime_t *idle, ktime_t now);
extern void fast_idle_account_add_iowait(int cpu, ktime_t *iowait, ktime_t now);

static inline void fast_sched_fork(struct task_struct *p)
{
	p->fast_sched = 0;
	p->itime = 0;
}

static inline bool fast_sched_is_enable(struct task_struct *p)
{
	return READ_ONCE(p->fast_enable) == FAST_SCHED_ENABLE;
}

#ifdef CONFIG_ARM64
static inline bool arch_fast_sched_support(void)
{
	return true;
}
#else
static inline bool arch_fast_sched_support(void)
{
	return false;
}
#endif
#else
static inline int fast_sched_enable(struct task_struct *p, int enable) { return -1; };
static inline void fast_idle_irq_enter(void) {};
static inline void fast_idle_irq_exit(void) {};
static inline void fast_sched_fork(struct task_struct *p) {};
static inline bool arch_fast_sched_support(void) { return false; };
static inline bool fast_sched_is_enable(struct task_struct *p) { return false; }

static inline void fast_idle_account_update_idle(int cpu, u64 *last_update_time,
	ktime_t *idle, ktime_t now) {};
static inline void fast_idle_account_update_iowait(int cpu, u64 *last_update_time,
	ktime_t *iowait, ktime_t now) {};
static inline void fast_idle_account_add_idle(int cpu, ktime_t *idle, ktime_t now) {};
static inline void fast_idle_account_add_iowait(int cpu, ktime_t *iowait, ktime_t now) {};
#endif

#endif
